<template>
  <div class="u-page u-box u-text-center u-lh-2 u-pt-50">
    <!-- 图标 -->
    <div>
      <u-icon
        :class="info.type == 'success' ? 'u-cl-primary' : 'u-cl-main'"
        :name="info.type == 'success' ? 'checkmark-circle' : 'info-circle'"
        size="100"
      ></u-icon>
    </div>
    <!-- 标题 -->
    <div
      class="u-fz-20 u-font-bold"
      :class="info.type == 'success' ? 'u-cl-primary' : 'u-cl-main'"
    >
      {{ info.title }}
    </div>
    <!-- 提示 -->
    <div class="u-cl-tips u-mt-15 u-mb-15" v-html="info.tips"></div>

    <!-- 按钮 -->
    <div style="bottom: 100rpx; position: fixed; width: 90%">
      <div style="margin-bottom: 10rpx" v-if="showBtn">
        <u-button type="primary" shape="circle" @click="onClick(info.action)">
          {{ info.btnText }}
        </u-button>
      </div>

      <u-button type="info" shape="circle" @click="onClick('goBack')">
        关闭
      </u-button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      taskNumber: "",
      partnerId: "",
      info: {},
      demand: {
        deliveryDate: "",
        finalPrice: "",
        paymentType: "",
        subject: "",
        taskNum: "",
        deadline: "",
        createUser: "",
      },
      nickName: "",
      showBtn: false,
      mode: 1,
      modes: {
        1: {
          type: "success",
          title: "提交成功!",
          btnText: "去分享",
          tips: "",
          action: "share",
        },
        2: {
          type: "success",
          title: "报名成功！",
          btnText: "关闭",
          tips: "",
          action: "goBack",
        },
        31: {
          type: "success",
          title: "完成初选！！",
          btnText: "关闭",
          tips: "",
          action: "goBack",
        },
        32: {
          type: "success",
          title: "完成初选！",
          btnText: "重新调整需求",
          tips: "",
          action: "update",
        },
        4: {
          type: "success",
          title: "已提交！",
          btnText: "关闭",
          tips: "",
          action: "goBack",
        },
        42: {
          type: "success",
          title: "提交成功!",
          tips: "已成功退回，等待拍档再次提交任务成果!",
          btnText: "关闭",
          action: "toWorkingPlatform",
        },
        51: {
          type: "success",
          title: "完成复选！",
          btnText: "关闭",
          tips: "",
          action: "goBack",
        },
        52: {
          type: "success",
          title: "完成复选！",
          btnText: "重新调整需求",
          tips: "",
          action: "update",
        },
        6: {
          type: "success",
          title: "确认成功！",
          btnText: "项目实施计划",
          tips: "",
          action: "showPlan",
        },
        8: {
          type: "success",
          title: "结算成功！",
          btnText: "关闭",
          tips: "",
          action: "goBack",
        },
        9: {
          type: "success",
          title: "提交成功！",
          btnText: "关闭",
          tips: "感谢您的评价与宝贵建议，欢迎您再次使用最佳拍档工作平台！",
          action: "goBack",
        },
      },
    };
  },
  onLoad(options) {
    this.info = this.modes[this.$query.mode || 1];
    this.mode = this.$query.mode;
    if (
      this.mode == "1" ||
      this.mode == "6" ||
      this.mode == "32" ||
      this.mode == "52"
    ) {
      this.showBtn = true;
    }
    this.taskNumber = this.$query.taskNumber;
    this.partnerId = this.$query.Partnerid;
    if (this.taskNumber) {
      this.getJobDetail().then((r) => {
        this.showMessage(this.mode);
        this.getNickName(this.demand.createUser);
      });
    }
    // 拍档提交成果，操作通知
    if (options.mode == 41) {
      this.info = {
        type: "success",
        title: "提交成功！",
        tips:
          '<span style="color:red;">' +
          options.workSubject +
          '</span>项目的<span style="color:red;">第' +
          options.subTaskSortNum +
          "期（" +
          options.subTaskSortNum +
          "/" +
          options.totalPeriods +
          '）</span>成果已提交，请耐心等待<span style="color:red;">' +
          options.initiatorName +
          "</span>验收，验收后佣金将于3个工作日内发放至您的收款账户。",
        btnText: "关闭",
        action: "goBack",
      };
    }

    // 用户确认验收 操作通知
    if (options.mode == 43) {
      this.info = {
        type: "success",
        title: "完成验收！",
        tips:
          '已完成<span style="color:red;">' +
          options.WorkSubject +
          '</span>项目的<span style="color:red;">第' +
          options.SubTaskSortNum +
          "期（" +
          options.SubTaskSortNum +
          "/" +
          options.TotalPeriods +
          '）</span>成果验收，验收结果已发送给<span style="color:red;">' +
          options.PartnerName +
          "</span>！平台将在3个工作日内安排本期佣金的发放！",
        btnText: "关闭",
        action: "goBack",
      };
    }
  },
  methods: {
    /**
     * 获取需求详情
     * @returns {Promise<void>}
     */
    async getJobDetail() {
      let result = await this.$u.api.unifyMiniRestGet({
        systemid: "meily",
        url: "/expert/job/" + this.taskNumber,
        loading: true, // 默认发起请求会有一个全局的Loading，设置false可去掉
      });
      if (result.code === "200" && result.data) {
        this.demand = result.data;
      } else {
        this.$u.toast(result.msg);
      }
    },
    async getNickName(userId) {
      if (!userId) {
        userId = this.$store.state.userInfo.userId;
      }
      let result = await this.$u.api.unifyMiniRestGet({
        systemid: "sso",
        url: "/user/cache/" + userId,
        loading: true, // 默认发起请求会有一个全局的Loading，设置false可去掉
      });
      if (result.code == "200" && result.data) {
        this.nickName = result.data.nickName;
      }
    },
    showMessage(mode) {
      if (mode == 1) {
        this.info.tips =
          "<span style=' color: #d71345'>" +
          this.demand.subject +
          "</span>需求已发布到工作大厅，并自动分配给所有符合条件的拍档们，请耐心等待报名信息。" +
          "<br>【紧急重要】" +
          "<br>您需在<span style=' color: #d71345'>" +
          this.demand.deadline +
          "</span>日前（含当天）完成本次项目的初选与复选，逾期筛选将以匹配失败终结项目，请知晓！" +
          "<br>【温馨提示】" +
          "<br>1、请务必关注微信公众号“最佳拍档工作平台”，报名通知将在公众号发布！" +
          "<br>2、为了能让更多的人能参与这项任务，建议您分享给好友或微信群，让更多的小伙伴参与进来哦～";
      }
      if (mode == 2) {
        this.info.tips =
          "您已报名参与<span style=' color: #d71345'>" +
          this.nickName +
          "</span>的" +
          "<span style=' color: #d71345'>" +
          this.demand.subject +
          "</span>项目，项目正在火热报名中，" +
          "<span style=' color: #d71345'>" +
          this.demand.deadline +
          "</span>前（含当天）将有初选结果，敬请等待！";
      }
      if (mode == 31) {
        this.info.tips =
          "<span style=' color: #d71345'>" +
          this.demand.subject +
          "</span>项目初选完毕，初选结果已发送给所有参与报名的拍档。" +
          "<br>【温馨提示】通过初选的拍档将会进行下一轮复选，请耐心等待对方的参与信息吧！";
      }
      if (mode == 32) {
        this.info.tips =
          "参与本次<span style=' color: #d71345'>" +
          this.demand.subject +
          "</span>项目的拍档皆不合适，建议您重新调整需求再次发布！" +
          "<br>【温馨提示】您可从项目时间、预算、需求等方面着手调整，提升报名质量。";
      }
      if (mode == 4) {
        this.info.tips =
          "您已接受<span style=' color: #d71345'>" +
          this.nickName +
          "</span>的<span style=' color: #d71345'>" +
          this.demand.subject +
          "</span> 项目复选邀请，项目实施计划已发送给用户，项目正在复选中，" +
          "<span style=' color: #d71345'>" +
          this.demand.deadline +
          "</span>（含当天）将有复选结果，敬请等待！";
      }
      if (mode == 51) {
        this.info.tips =
          "<span style=' color: #d71345'>" +
          this.demand.subject +
          "</span>项目复选完毕，复选结果已发送给中标的拍档。" +
          "<br>【温馨提示】通过复选的拍档将会进行项目实施计划确认，请耐心等待对方的参与信息吧！";
      }
      if (mode == 52) {
        this.info.tips =
          "参与本次<span style=' color: #d71345'>" +
          this.demand.subject +
          "</span>项目的拍档皆不合适，建议您重新调整需求再次发布！" +
          "<br>【温馨提示】您可从项目时间、预算、需求等方面着手调整，提升报名质量。";
      }
      if (mode == 6) {
        let len = this.demand.paymentType.split(":").length;
        this.info.tips =
          "您已确认参与<span style=' color: #d71345'>" +
          this.nickName +
          "</span>的<span style=' color: #d71345'>" +
          this.demand.subject +
          "</span>项目，项目已启动！" +
          "项目金额<span style=' color: #d71345'>" +
          this.demand.finalPrice +
          "</span>元，一共分<span style=' color: #d71345'>" +
          len +
          "</span>期提交工作" +
          "成果，分期付款比例<span style=''>" +
          this.demand.paymentType +
          "</span>，请严格按照实施计划完成工作任务。" +
          "<br>【温馨提示】 " +
          "<br>目前已开放第<span style=' color: #d71345'>1</span>期<span style=' color: #d71345'>（1/" +
          len +
          "）</span>的交付入口，请您在<span style=' color: #d71345'>" +
          this.demand.deliveryDate +
          "</span>" +
          "日前（含当天）提交工作成果。点击下方按钮查看项目实施计划，前往“工作台”找对应的工作待办即可提交工作成果！";
      }
    },
    /**
     * 按钮点击
     */
    onClick(action) {
      switch (action) {
        // 关闭
        case "goBack":
          uni.reLaunch({ url: "/pages/index/index" });
          break;
        // 分享需求
        case "share":
          uni.redirectTo({
            url:
              "/pages_private_scene1/ExpertCooperate/grabJob?taskNumber=" +
              this.taskNumber +
              "&isShow=0",
          });
          break;
        //调整需求
        case "update":
          uni.redirectTo({
            url:
              "/pages_private_scene1/ExpertCooperate/publishJob?taskNumber=" +
              this.taskNumber,
          });
          break;
        // 完善资料
        case "improve":
          uni.reLaunch({
            url: "/pages_tabbar_contact/personal_contact/personal/improve",
          });
          break;
        case "toPersonal":
          uni.reLaunch({ url: "/pages/index/incomeIndex" });
          break;
        case "toWorkingPlatform":
          uni.reLaunch({
            url: "/pages_tabbar_contact/index_contact/WorkBench",
          });
          break;
        case "showPlan":
          uni.reLaunch({
            url:
              "/pages_private_scene1/ExpertCooperate/partnerWorkPlan?taskNumber=" +
              this.taskNumber +
              "&pubPlan=1&userId=" +
              this.partnerId,
          });
          break;
        default:
          break;
      }
    },
  },
};
</script>

<style lang="scss" scoped></style>
